<!--
 * @Author: lbt666 '1319451895@qq.com'
 * @Date: 2022-07-25 13:42:39
 * @LastEditors: lbt666 1319451895@qq.com
 * @LastEditTime: 2023-07-30 15:10:55
 * @Description: 
-->
<template>
  <router-view v-slot="{ Component }">
    <component :is="Component" :key="$route.name" />
  </router-view>
</template>
<script setup lang="ts" name="APP">
import { addressNonce, isLoopInviter } from '@/api/request'
import contractStore from '@/store/modules/contract'
import { reactive, watch, computed, onMounted, toRaw } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const appStore = contractStore();
const includeList = reactive<string[]>([])
const route = useRoute()
const router = useRouter()
const address = computed(() => {
  return toRaw<string>(appStore.address)
})

interface axiosData {
  data: number
}

watch(() => route, (newVal, oldVal) => {
  if (newVal.meta.keepAlive && includeList.indexOf(<string>newVal.name) === -1) {
    includeList.push(<string>newVal.name);
  }
}, { deep: true })

watch(address, async (value, oldvalue) => {
  let res = <axiosData>await addressNonce(value || oldvalue)
  appStore.SET_Nonce(res.data)
})

onMounted(async () => {
  // let geturl = location.href
  // if (geturl.indexOf('?') == -1) {
  //   return
  // }
  // let getqyinfo = geturl.split('?')[geturl.split('?').length - 1]
  // let getqys = getqyinfo.split('&')
  // let obj = {} as any  //创建空对象，接收截取的参数
  // for (let i = 0; i < getqys.length; i++) {
  //   let item = getqys[i].split('=')
  //   let key = item[0]
  //   let value = item[1]
  //   obj[key] = value
  // }
  // let parms = obj.address
  // console.log('parms', parms)
  // if (parms) {
  //   await isLoopInviter(parms)
  // }
})
</script>